import React,{ useState, useImperativeHandle } from 'react'

 function Hello(props, ref) {
     const [count, setCount ] = useState(0)
     useImperativeHandle(ref, () => {
         return {
             aa: "bao",
             add() {
                setCount(a => ++a)
             }
         }
     })
     function getAdd() {
        setCount(a => ++a)
     }
  return (
    <div>Hello
        <button onClick={getAdd } > count +1 </button>
        <div>{count}</div>
    </div>
  )
}
export default React.forwardRef(Hello)

// import React, { Component } from 'react'   //  类组件 可以使用 ref 直接 获取

// export default class Hello extends Component {
//   render() {
//     return (
//       <div>Hello</div>
//     )
//   }
// }
